using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_Shop_TryCommentManage : Member, IRequiresSessionState
{
	protected int ProductID = 0;
	protected Repeater Repeater1;
	protected Label lbPage;
	protected Panel Panel1;
	protected Repeater Repeater2;
	protected Button BatchAudit;
	protected Button BatchDel;
	protected Label lbPage2;
	protected Panel Panel2;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (base.Request.QueryString["ProductID"] != null)
			{
				try
				{
					this.ProductID = int.Parse(base.Request.QueryString["ProductID"].ToString());
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[]
					{
						"正常操作"
					});
					this.ProductID = 0;
				}
			}
			if (base.Request.QueryString["tag"] != null)
			{
				this.Panel2.Visible = true;
				this.Panel1.Visible = false;
				this.TryBindComment();
			}
			else
			{
				this.Panel2.Visible = false;
				this.Panel1.Visible = true;
				this.BindTryProduct();
			}
		}
	}
	public void BindTryProduct()
	{
		CurrPageLinks currPageLinks = new CurrPageLinks();
		int num = 1;
		if (base.Request.QueryString["pageindex"] != null)
		{
			if (base.Request.QueryString["pageindex"].ToString() != "")
			{
				try
				{
					num = int.Parse(base.Request.QueryString["pageindex"].ToString());
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[]
					{
						"正常操作"
					});
					num = 1;
				}
			}
		}
		int pCount = this.conn.ExecuteCount("select count(*) from HLShop_TryProduct where SalerID=" + base.user.UserID);
		int num2 = (num - 1) * 16;
		DataTable dataTable = this.conn.GetDataTable(string.Concat(new object[]
		{
			"select top 16 * from HLShop_TryProduct where TryID not in(select top ",
			num2,
			" TryID from HLShop_TryProduct where SalerID=",
			base.user.UserID,
			" order by CreateTime Desc) and SalerID=",
			base.user.UserID,
			" order by CreateTime Desc"
		}));
		this.Repeater1.DataSource = dataTable;
		this.Repeater1.DataBind();
		this.lbPage.Text = currPageLinks.CurrPageLink(num, 16, pCount, "个商品", "/Member/Shop_TryCommentManage.aspx?pageindex");
	}
	public string ShowClass(string ClassID)
	{
		string result = "";
		DataTable dataTable = this.conn.GetDataTable("select * from HLShop_Class where ClassID=" + int.Parse(ClassID));
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			result = dataTable.Rows[0]["ClassName"].ToString();
		}
		dataTable.Dispose();
		return result;
	}
	public string GetCommentQuantity(string ProductID)
	{
		return this.conn.ExecuteCount("select count(*) from HLShop_TryComment where ProductID=" + int.Parse(ProductID)).ToString();
	}
	public void TryBindComment()
	{
		CurrPageLinks currPageLinks = new CurrPageLinks();
		int num = 1;
		if (base.Request.QueryString["pageindex"] != null)
		{
			if (base.Request.QueryString["pageindex"].ToString() != "")
			{
				try
				{
					num = int.Parse(base.Request.QueryString["pageindex"].ToString());
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[]
					{
						"正常操作"
					});
					num = 1;
				}
			}
		}
		int pCount = this.conn.ExecuteCount("select count(*) from HLShop_TryComment where ProductID=" + this.ProductID);
		int num2 = (num - 1) * 16;
		DataTable dataTable = this.conn.GetDataTable(string.Concat(new object[]
		{
			"select top 16 * from HLShop_TryComment where CommentID not in(select top ",
			num2,
			" CommentID from HLShop_TryComment where ProductID=",
			this.ProductID,
			" order by CreateTime Desc) and ProductID=",
			this.ProductID,
			"  order by CreateTime Desc"
		}));
		this.Repeater2.DataSource = dataTable;
		this.Repeater2.DataBind();
		this.lbPage2.Text = currPageLinks.CurrPageLink(num, 16, pCount, "个评论", "/Member/Shop_TryCommentManage.aspx?pageindex&tag=Show");
	}
	public string ShowUserName(string UserID)
	{
		string result = "未知";
		DataTable dataTable = this.conn.GetDataTable("select UserName from HL_User where UserID=" + int.Parse(UserID));
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			result = dataTable.Rows[0]["UserName"].ToString();
		}
		dataTable.Dispose();
		return result;
	}
	public string ShowStatus(string CommentID)
	{
		string result = "未审核";
		int num = 0;
		DataTable dataTable = this.conn.GetDataTable("select audit from HLShop_TryComment where CommentID=" + int.Parse(CommentID));
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			try
			{
				num = int.Parse(dataTable.Rows[0]["audit"].ToString());
			}
			catch (Exception ex)
			{
				ex.WriteErrorLog(new string[]
				{
					"正常操作"
				});
				num = 0;
			}
			if (num == 1)
			{
				result = "已审核";
			}
		}
		dataTable.Dispose();
		return result;
	}
	public string ShowProductName(string StrProductID)
	{
		string result = "";
		DataTable dataTable = this.conn.GetDataTable("select ProductName from HLShop_TryProduct where TryID=" + int.Parse(StrProductID));
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			result = dataTable.Rows[0]["ProductName"].ToString();
		}
		dataTable.Dispose();
		return result;
	}
	protected void BatchDel_Click(object sender, EventArgs e)
	{
		int num = 0;
		string text = "";
		for (int i = 0; i < this.Repeater2.Items.Count; i++)
		{
			HiddenField hiddenField = (HiddenField)this.Repeater2.Items[i].FindControl("HidCommentID");
			CheckBox checkBox = (CheckBox)this.Repeater2.Items[i].FindControl("CheckBox1");
			if (checkBox.Checked)
			{
				text = text + hiddenField.Value + ",";
			}
		}
		try
		{
			num = this.conn.Execute("delete HLShop_TryComment where CommentID in(" + text.Substring(0, text.Length - 1) + ")");
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[]
			{
				"正常操作"
			});
			num = 0;
		}
		if (num > 0)
		{
			this.TryBindComment();
		}
	}
	protected void BatchAudit_Click(object sender, EventArgs e)
	{
		int num = 0;
		for (int i = 0; i < this.Repeater2.Items.Count; i++)
		{
			CheckBox checkBox = (CheckBox)this.Repeater2.Items[i].FindControl("CheckBox1");
			HiddenField hiddenField = (HiddenField)this.Repeater2.Items[i].FindControl("HidCommentID");
			if (checkBox.Checked)
			{
				try
				{
					num = this.conn.Execute("update HLShop_TryComment set audit=1 where CommentID=" + int.Parse(hiddenField.Value));
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[]
					{
						"正常操作"
					});
					num = 0;
				}
			}
		}
		if (num == 1)
		{
			this.TryBindComment();
		}
	}
	protected void LbtDel_Click(object sender, EventArgs e)
	{
		int num = 0;
		LinkButton linkButton = sender as LinkButton;
		RepeaterItem repeaterItem = linkButton.Parent as RepeaterItem;
		HiddenField hiddenField = repeaterItem.FindControl("HidCommentID") as HiddenField;
		try
		{
			num = this.conn.Execute("delete HLShop_TryComment where CommentID=" + int.Parse(hiddenField.Value));
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[]
			{
				"正常操作"
			});
			num = 0;
		}
		if (num == 1)
		{
			this.TryBindComment();
		}
	}
	protected void LbtAudit_Click(object sender, EventArgs e)
	{
		int num = 0;
		LinkButton linkButton = sender as LinkButton;
		RepeaterItem repeaterItem = linkButton.Parent as RepeaterItem;
		HiddenField hiddenField = repeaterItem.FindControl("HidCommentID") as HiddenField;
		try
		{
			num = this.conn.Execute("update HLShop_TryComment set audit=1 where CommentID=" + int.Parse(hiddenField.Value));
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[]
			{
				"正常操作"
			});
			num = 0;
		}
		if (num == 1)
		{
			this.TryBindComment();
		}
	}
}
